"""
__author__ = 'berlinyoung'
@File   :single_stock_page.py
@Date   :2022/6/12 21:57
-*- coding: utf-8 -*-
"""
import time

from appium.webdriver.common.mobileby import MobileBy

from anxinstock_mobile.page.base import Base


class SingleStockPage(Base):

    # def deal_buy(self):
    #     self.find_and_click(MobileBy.XPATH,"//*[@text='交易']")
        # self.find_and_click(MobileBy.XPATH,"//*[@text='闪买']")

    def sale_common(self):
        self.find_and_click(MobileBy.XPATH, "//*[@text='交易']")
        self.find_and_click(MobileBy.XPATH, "//*[@text='闪卖']")
        # 将登录分为两种情况，一种已登录，一种未登录，通过元素是否存在进行走向。并封装到base
        # x每270一个数字格，y约每200一个数字格
        time.sleep(1)
        if "et_price" in self.driver.page_source:
            pass
        else:
            self.tap_login()
        # 当日跌停价
        # limit_down = self.find_get(MobileBy.ID,"tv_limit_down")
        limit_up = self.find_get(MobileBy.ID, "tv_limit_up")
        self.find_and_keys(MobileBy.ID, "et_price",limit_up)


    # sell out
    def sell_all(self):
        self.sale_common()
        self.find_and_click(MobileBy.XPATH,"//*[@text='全仓']")
        self.deal_confirm()

    # sell part
    def sell_part(self,amount):
        self.sale_common()
        self.find_and_keys(MobileBy.ID,"et_count",amount)
        self.deal_confirm()
